package com.example.post.services.impl;

import com.example.post.mapper.MessageMapper;
import com.example.post.model.Message;
import com.example.post.services.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageMapper messageMapper;
    public void sendMessage(int senderId, int receiverId,String content) {
        Message message=new Message();
        message.setSenderId(senderId);
        message.setReceiverId(receiverId);
        message.setContent(content);
        message.setCreateTime(LocalDateTime.now());
        messageMapper.insertMessage(message);
    }
    public List<Message> getMessages(int userId) {
        return messageMapper.getMessagesByUserId(userId);
    }

    public List<Message> getMyMessages(int userId) {
        return messageMapper.getMessages(userId);
    }
}
